package com.mail.server.controller;


import com.mail.model.db.UmsResourceCategory;
import com.mail.server.common.R;
import com.mail.server.service.UmsResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资源分类表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/resourceCategory")
public class UmsResourceCategoryController {
	@Autowired
	private UmsResourceCategoryService umsResourceCategoryService;

	/**
	 * 查询所有后台资源分类
	 * 接口地址:/resourceCategory/listAll
	 * @return
	 */
	@GetMapping("/listAll")
	public R<List<UmsResourceCategory>> listAll(){
		List<UmsResourceCategory> umsResourceCategories = umsResourceCategoryService.listAll();
		return R.success(umsResourceCategories, "操作成功!");
	}

	@PostMapping("/create")
	public R create(@RequestBody UmsResourceCategory category){
		return umsResourceCategoryService.create(category);
	}

	/**
	 * 根据ID删除后台资源
	 * @param id
	 * @return
	 */
	@PostMapping("/delete/{id}")
	public R deleteCategoryById(@PathVariable Integer id){
		umsResourceCategoryService.deleteCategoryById(Long.valueOf(id));
		return R.success(null);
	}

	/**
	 * 修改后台资源分类
	 * @param id
	 * @param resourceCategory
	 * @return
	 */
	@PostMapping("/update/{id}")
	public R updateCategoryById(@PathVariable Integer id, @RequestBody UmsResourceCategory resourceCategory){
		umsResourceCategoryService.updateCategoryById(Long.valueOf(id),resourceCategory);
		return R.success(null);
	}
}
